/**
 * DOM 操作封装
 */
let local=require('../utils/local')

//1.封装获取单个元素对象
function getEle(selector) {
    return document.querySelector(selector)
}

//1.封装获取多个元素对象
function getEleAll(selector) {
    return document.querySelectorAll(selector)
}


//文档加载事件:
/*
    onload: 所有资源加载完成后,才执行js代码
    DOMContentLoaded: 只需要DOM加载完成后,就可以执行js代码
*/
/* dom加载完毕 */
function ready(callback) {
    window.addEventListener('DOMContentLoaded', function () {
        callback()
    })
}

//改写标准注册事件
function addEvent(obj, callback, type = "click") {
    document.querySelector(obj).addEventListener(type, function () {
        callback()
    })
}
//底部菜单
//底部菜单
function bMenu(pos) {
  getEle('body').innerHTML += `
  <footer class="bgfff">
  <ul>
    <li><a href="home.html" class="${pos == 'home' ? 'active' : ''}"><span class="iconfont icon-home"></span><span>首页</span></a></li>
    <li><a href="motion.html" class="${pos == 'motion' ? 'active' : ''}"><span class="iconfont icon-sport"></span><span>运动</span></a></li>
    <li><a href="circle.html" class="${pos == 'circle' ? 'active' : ''}"><span class="iconfont icon-circle"></span><span>圈子</span></a></li>
    <li><a href="my.html" class="${pos == 'my' ? 'active' : ''}"><span class="iconfont icon-mine"></span><span>我的</span></a></li>
  </ul>
</footer>
  `
}

// 判断用户是否登录

// 判断用户是否登录
//判定是否登录
function isLogin() {
  //获取token
  let token = local.get('token');
  //判定token
  if (!token) {
    
      location.href = 'login.html'
  }
}


//暴露出去
module.exports = {
    getEle,
    getEleAll,
    ready,
    addEvent,
    bMenu,
    isLogin,

}



